package activitytest.example.com.application;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.ListViewCompat;
import android.util.Log;
import android.widget.ListView;

/**
 * Created by zhanyihong on 2017/12/6.
 */

public  class ContactListActivity extends Activity{
    protected  static final  String tag ="ContactListActivity";
    private ListView lv_conTent;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contact_list);
        initUI();
        initDate();
    }

    private void initDate() {
        new Thread(){
            public void run(){
                ContentResolver contentresolver= getContentResolver();

                Cursor cursor= contentresolver.query(Uri.parse("content://com.android.contacts/raw_contacts"),
                        new String[]{"contact_id"},
                        null,
                        null,
                        null

                );
                while (cursor.moveToNext()){
                    String id = cursor.getString(0);
                    Log.i(tag,"id="+id);
                }
                cursor.close();
            }
        }.start();

    }

    private void initUI() {
        lv_conTent = (ListView) findViewById(R.id.lv_conTent);

    }

}
